package com.hnevc.restaurant.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hnevc.restaurant.annotation.auth.Auth;
import com.hnevc.restaurant.entity.Food;
import com.hnevc.restaurant.service.FoodService;




@Controller
@RequestMapping("/Food")
public class FoodController {
	@Resource
	FoodService foodService;
	/*
	 * 添加
	 * */
	@Auth
	@RequestMapping(value="/addFood",method=RequestMethod.POST)
	@ResponseBody
	public Food addFood(@RequestBody Food food) {
		int count = foodService.insert(food);
		//List<Food> foods  = foodService.findFoods(food);
		if(count>=1)
			return food;
		else 
			return null;
	}
	/*
	 * 删除
	 */
	
	@RequestMapping(value="/delFood/{id}")
	public int delFood(@PathVariable String id) {
		int count = foodService.deleteById(id);
		return count;
	}
	@RequestMapping(value="/doFindFoodsJson",method=RequestMethod.POST)
	@ResponseBody
	public List<Food> findFoods2(@RequestBody Food food){
		List<Food> foods  = foodService.findFoods(food);
		return foods;
	}
	@RequestMapping(value="/doFindFoods",method=RequestMethod.POST)
	@ResponseBody
	public List<Food> findFoods3(Food food){
		List<Food> foods  = foodService.findFoods(food);
		return foods;
	}
	
	@RequestMapping(value="/findFoods")
	public String findFoods(){
		return "FindFood";
	}
	/*
	 * 获取所有
	 *
	 */
	@Auth
	@RequestMapping(value="/getFoods")
	@ResponseBody
	public List<Food> getAllFoods() {
		List<Food> foods  = foodService.getAllFoods();
		return foods;
	}
	/*
	 * 获取一个
	 * */
	@RequestMapping(value="/ShowFood/{id}")
	@ResponseBody
	public Food getFoodById(@PathVariable String id) {
		Food food  = foodService.getFoodById(id);
		return food;
	}
	
	/*
	 * 修改
	 */
	@RequestMapping(value="/updateFood",method=RequestMethod.POST)
	public int updateFood(@RequestBody Food food) {
		return foodService.updateByPrimaryKey(food);
	}
	
	 
}
